﻿using System;
using System.Diagnostics;

namespace Framework
{
    public class FlashPrinter
    {
        private const string flashPrinter = @"I:\Program Files (x86)\Macromedia\FlashPaper 2\FlashPrinter.exe";
        public static void Transformation(string path, string targetPath)
        {
            try
            {
                var p = new Process
                            {
                                StartInfo =
                                    {
                                        FileName = "cmd",
                                        UseShellExecute = false,
                                        RedirectStandardInput = true,
                                        RedirectStandardOutput = true,
                                        RedirectStandardError = true,
                                        CreateNoWindow = true,
                                        WindowStyle = ProcessWindowStyle.Hidden
                                    }
                            };
                p.Start();
                string s = flashPrinter + path + " -o " + targetPath;
                p.StandardInput.WriteLine(s);
                p.StandardInput.WriteLine("exit");
                string strOutput = p.StandardOutput.ReadToEnd();
                Console.WriteLine(strOutput);
                p.WaitForExit();
                p.Close();
                var processe = new Process();
                var startInfos = new ProcessStartInfo();
                string docFile = path;
                string swfFile = targetPath;
                startInfos.FileName = flashPrinter;
                startInfos.Arguments = docFile + " -o " + swfFile;
                startInfos.UseShellExecute = false;     //不使用系统外壳程序启动
                startInfos.RedirectStandardInput = false;   //不重定向输入
                startInfos.RedirectStandardOutput = false;   //重定向输出
                startInfos.CreateNoWindow = true;     //不创建窗口
                processe.StartInfo = startInfos;
                processe.Start();
                var startInfo = new ProcessStartInfo(flashPrinter);
                if (String.IsNullOrEmpty(targetPath))
                {
                    return;
                }

                startInfo.Arguments = String.Concat(path, " -o ", targetPath);
                var process = new Process { StartInfo = startInfo };
                process.Start();
                process.WaitForExit();
                process.Close();

             
                    string _oldFilePath = path;
                    string _swfFilePath = targetPath;
                    var pss = new Process
                                  {
                                      StartInfo =
                                          {
                                              CreateNoWindow = false,
                                              FileName = flashPrinter,
                                              Arguments =
                                                  string.Format("{0} {1} -o {2}", flashPrinter, _oldFilePath, _swfFilePath)
                                          }
                                  };
                pss.Start();
                    while (!pss.HasExited)
                    {
                    }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

    }
}
